include <dimlines.scad>  // @see https://github.com/pwpearson/dimensional-drawings/tree/master

$fn=15;
// some colors
color_copper="#FFDD00FF";
color_ladder="#2F4F4F22";
color_dimension="#2F4F4FFF";

// dimensions
dimension_width=.5;

// Ladderline CQ562:
// @see https://kabel-kusch.de/Koaxkabel/CQ553-CQ562/FEEDER.htm
// 300 Ohm, max. 1KW, width 10 mm, dia of wire 1.5mm, distance between wires 7 mm
ladderline_type="CQ562";
ladderline_ohm="300 Ohm";
velocity_factor=0.905;   // Velocity factor of ladderline CQ562
conducter_dia=1.5;
conducter_distance=7.0; // center to center
ladderline_width=10.0;
max_power="1 KW";
echo("----------------------------------------");
echo("Ladderline type: ", ladderline_type);
echo("velocity_factor: " , velocity_factor);
echo("Resitance: ", ladderline_ohm );
echo("diameter of conducter ~ ", conducter_dia, "mm");
echo("center distance between conducters ~ ", conducter_distance, "mm");
echo("width of ladderline ~ ", ladderline_width, "mm");
echo("max. power: ", max_power);
echo("----------------------------------------");

// length of cut's in ladderline
cut_len=5;

// @see https://m0ukd.com/calculators/slim-jim-and-j-pole-calculator/
// @see http://oe1iah.at/images/Antennen/PraesidentenAntenneMIKE.pdf
// @see http://oe1iah.at/Hardware/Antennen/SlimJim2-70.shtml
// @see https://www.everythingrf.com/rf-calculators/frequency-to-wavelength
// λ = C/f
//
//λ (Lambda) = Wavelength in meters
//c = Speed of Light (299792458 m/s)
//f = Frequency

// Speed of Light (299792458 m/s)
speed_light=299792458; 


// Center frequency in 2 meter band in MHz
freq_2m=145;
echo("Center frequency for 2 meter = " , freq_2m, " MHz");
// λ = C/f
wavelen_2m = speed_light/freq_2m;
echo("Wavelength for 2 meter band = " , wavelen_2m);

// Wavelength considering velocity factor
len100_2m=wavelen_2m*velocity_factor/1000;
// Overall length (λ*0.75)*vf
len075_2m=(wavelen_2m*0.75)*velocity_factor/1000; // total length of antenna
echo("Total length of antenna = " , len075_2m);
//Half wave radiator section (λ/2)*vf
len050_2m=(wavelen_2m*0.5)*velocity_factor/1000;
// Quarter wave matching section (λ/4)*vf
len025_2m=(wavelen_2m*0.25)*velocity_factor/1000; // length of matching section
echo("Length of matching section = " , len025_2m);

// How is the 50Ω feed point calculated?
// Literature is not clear: 
// some say its 3.2 mm others use 3.2 mm for the lower end of the cut etc. 
// Here is a calculation from one website:
//      Adjust for 1:1 SWR. (λ/40)*vf
//      feedpoint=(wavelen_2m/40)*velocity_factor/1000;
// I use 30 mm for the lower end of the cut and test it out then:
feedpoint=30;
echo("Distance to feedpoint = " , feedpoint, "mm");

echo("----------------------------------------");
echo("wavelen_2m = " , wavelen_2m, "m");
echo("len100_2m  = " , len100_2m, "mm");
echo("len075_2m  = " , len075_2m, "mm");
echo("len050_2m  = " , len050_2m, "mm");
echo("len025_2m  = " , len025_2m, "mm");
echo("----------------------------------------");
///////////////////////////////////////////////////////////////////////////////////
// Main
///////////////////////////////////////////////////////////////////////////////////
makeLadderline();
makeBridge();
drawDimensions();

///////////////////////////////////////////////////////////////////////////////////
//
///////////////////////////////////////////////////////////////////////////////////
module drawDimensions()
{
    // base line
    color(color_dimension)
    translate([ladderline_width, 0, 0])
    line(length=ladderline_width*4, width=dimension_width, height=dimension_width/2,
    left_arrow=false, right_arrow=false);
    // feedpoint line
    color(color_dimension)
    translate([ladderline_width, 0, feedpoint])
    line(length=ladderline_width*1.5, width=dimension_width, height=dimension_width/2,
    left_arrow=false, right_arrow=false);
    //quarter wave matching section line
    color(color_dimension)
    translate([ladderline_width, 0, len025_2m])
    line(length=ladderline_width*2.5, width=dimension_width, height=dimension_width/2,
    left_arrow=false, right_arrow=false);
    //top line for total length
    color(color_dimension)
    translate([ladderline_width, 0, len075_2m])
    line(length=ladderline_width*3.5, width=dimension_width, height=dimension_width/2,
    left_arrow=false, right_arrow=false);


    // feedpoint dimension
    color(color_dimension)
    translate([ladderline_width*2, 0, 0])
    rotate([0,-90,90])
    dimensions(feedpoint, dimension_width);  
    // cut width dimension
    color(color_dimension)
    translate([ladderline_width*2, 0, feedpoint])
    rotate([0,-90,90])
    dimensions(cut_len, dimension_width, DIM_OUTSIDE);
    // quarter wave matching section dimension
    color(color_dimension)
    translate([ladderline_width*3, 0, 0])
    rotate([0,-90,90])
    dimensions(len025_2m, dimension_width);
    // cut width dimension
    color(color_dimension)
    translate([ladderline_width*3, 0, len025_2m])
    rotate([0,-90,90])
    dimensions(cut_len, dimension_width, DIM_OUTSIDE);
    // quarter wave matching section dimension
    color(color_dimension)
    translate([ladderline_width*4, 0, 0])
    rotate([0,-90,90])
    dimensions(len075_2m, dimension_width);
}

///////////////////////////////////////////////////////////////////////////////////
//
///////////////////////////////////////////////////////////////////////////////////
module makeLadderline()
{
    // right conductor
    difference() // make cut for quarter wave matching section (λ/4)*vf
    {
    translate([conducter_distance/2, 0,0])
    color(color_copper)
    cylinder(h=len075_2m, d=conducter_dia, center=false);
    
    // cut for quarter wave matching section (λ/4)*vf
    translate([(conducter_distance-conducter_dia)/2-0.5,-ladderline_width/2,len025_2m+0.1])
    cube([ladderline_width,ladderline_width,cut_len-0.2], center=false);
    }
    // left conductor
    translate([-conducter_distance/2,0,0])
    color(color_copper)
    cylinder(h=len075_2m, d=conducter_dia, center=false);
    
    // make the isolation plastic
    
    difference() // make cuts for feedpoint and quarter wave matching section (λ/4)*vf
    {
    // ladderline
    translate([0,0,len075_2m/2+conducter_dia/2])
    color(color_ladder)
    cube([ladderline_width,conducter_dia+1,len075_2m-conducter_dia], center=true);
    // right feedpoint cut
    translate([(conducter_distance-conducter_dia)/2-0.5,-ladderline_width/2,feedpoint])
    cube([ladderline_width,ladderline_width,cut_len], center=false);
    // left feedpoint cut
    translate([-ladderline_width-((conducter_distance-conducter_dia)/2-0.5),-ladderline_width/2,feedpoint])
    cube([ladderline_width,ladderline_width,cut_len], center=false);
    // cut for quarter wave matching section (λ/4)*vf
    translate([(conducter_distance-conducter_dia)/2-0.5,-ladderline_width/2,len025_2m])
    cube([ladderline_width,ladderline_width,cut_len], center=false);
    }

}
///////////////////////////////////////////////////////////////////////////////////
//
///////////////////////////////////////////////////////////////////////////////////
module makeBridge()
{
    // connect the two conducters at the bottom of the antenna
    translate([0,0,conducter_dia/2])
    rotate([0,90,0])
    color(color_copper)
    cylinder(h=(conducter_distance+conducter_dia), d=conducter_dia, center=true);
}
///////////////////////////////////////////////////////////////////////////////////
//
///////////////////////////////////////////////////////////////////////////////////
